#!/bin/ash
#
# /etc/rc: system boot script
#

echo "The system is coming up.  Please wait."

# Load configuration
. /etc/rc.conf

# Start udev
/bin/mount -n -t proc none /proc
/bin/mount -n -t sysfs none /sys
/sbin/start_udev

# Mount root read-only
/bin/mount -n -o remount,ro /

# Check filesystems
/sbin/fsck -A -T -C -a
if [ $? -gt 1 ]; then
	echo
	echo "***************  FILESYSTEM CHECK FAILED  ******************"
	echo "*                                                          *"
	echo "*  Please repair manually and reboot. Note that the root   *"
	echo "*  file system is currently mounted read-only. To remount  *"
	echo "*  it read-write type: mount -n -o remount,rw /            *"
	echo "*  When you exit the maintainance shell the system will    *"
	echo "*  reboot automatically.                                   *"
	echo "*                                                          *"
	echo "************************************************************"
	echo
	/sbin/sulogin -p
	echo "Automatic reboot in progress..."
	/bin/umount -a -r
	/bin/mount -n -o remount,ro /
	/sbin/reboot -f
	exit 0
fi

# Mount local filesystems
/bin/mount -n -o remount,rw /
/bin/umount /sys /proc
/bin/rm -f /etc/mtab*
/bin/touch /etc/mtab
/bin/mount -o remount,rw /

cat /proc/filesystems | tail -1
/bin/mount -a -O no_netdev

echo "Done"
# Activate swap
/sbin/swapon -a

# Clean up misc files
: > /var/run/utmp
/bin/rm -rf /forcefsck /fastboot /etc/nologin /etc/shutdownpid
(cd /var/run && /usr/bin/find . -name "*.pid" -delete)
(cd /var/lock && /usr/bin/find . ! -type d -delete)
(cd /tmp && /usr/bin/find . ! -name . -delete)
/bin/mkdir -m 1777 /tmp/.ICE-unix

# Set kernel variables
/sbin/sysctl -p > /dev/null

# Update shared library links
/sbin/ldconfig

# Configure host name
if [ "$HOSTNAME" ]; then
	echo "hostname: $HOSTNAME"
	/bin/hostname $HOSTNAME
fi

# Load random seed
/bin/cat /var/lib/urandom/seed > /dev/urandom

# Configure system clock
if [ "$TIMEZONE" ]; then
	/bin/ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
fi
/sbin/hwclock --hctosys

# Load console font
if [ "$FONT" ]; then
	echo "font: $FONT"
	/usr/bin/setfont $FONT
fi

# Load console keymap
if [ "$KEYMAP" ]; then
	echo "keyboard: $KEYMAP"
	/bin/loadkeys -q $KEYMAP
fi

# Screen blanks after 15 minutes idle time
/usr/bin/setterm -blank 15

# Run module initialization script
if [ -x /etc/rc.modules ]; then
	/etc/rc.modules
fi

# Save boot messages
/bin/dmesg > /var/log/boot

# End of file
